<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
	<meta name="author" content="wangzhichao">
	<title>申请单管理/任务单管理</title>
	<script language="javascript" src="../script/common.js" type="text/javascript"></script>
	<script language="javascript" type="text/javascript">
	//全局变量
	var qt = {};				//数据表格对象
	var orderId="";					//申请单类型
	var type="";					//卡片类型
	var titlename="";				//标题名称
	var cOrg;				//取当前地址
	var detail_editable;
	//页面控件初始化
	function load(){
		Eui.showNavigation();//导航
		setPages(["listview","detview","detread","listview1"])
		cOrg = Common.cOrg()
		//初始化申请单状态("新建","申请","通过","拒绝","确认")

		var statusList
		if(cOrg.orgLevel == Constants.ORG_LEVEL_HQ){
			 statusList = Common.getSubsetItems("cardbill_status", [Constants.CARDBILL_STATUS_NEW, Constants.CARDBILL_STATUS_CONFIRM]);
		}else{
			 statusList = Common.getSubsetItems("cardbill_status", [Constants.CARDBILL_STATUS_NEW, Constants.CARDBILL_STATUS_REQUEST, Constants.CARDBILL_STATUS_PASSED,Constants.CARDBILL_STATUS_REJECTED]);
		}
		
			 	
		Common.initDict(searchForm.status,statusList,"全 部");	
		
		if(cOrg.orgLevel == Constants.ORG_LEVEL_HQ){
			$("restrictedOrgTd").innerHTML = "<label>使用区域</label> <select name='restrictedOrg'><option></option></select>";
			DWR.call("storeQueryService.getCardAreas",function(result){
				Common.initDict(searchForm.restrictedOrg,result,"全 部","id","name");	
				Common.initDict(demandform.restrictedOrg,result,null,"id","name");
			})
			
		}	
		Eui.initBeginDateInput("beginDateTd","起始日期","searchForm","startrequestDate","endrequestDate","_pastDate");
		Eui.initEndDateInput("endDateTd","结束日期","searchForm","startrequestDate","endrequestDate","date");
		createTable();
	}
	
	//生成查询语句
	function createTable(){
		var columns = [];
		columns[0] = {render:numFunc};
		var discolumns;
		var xmlShow = "manage_request_query";
		columns[3] = {defOrder:true}
		if(cOrg.orgLevel == Constants.ORG_LEVEL_HQ){
			columns[9] = {title:"操作",width:12,render:operationFunc,align:"center",order:false};
			//discolumns = [0,1,2,3,4,5,6,7,8]
			titlename = "制卡任务单列表"
		}else{
			xmlShow = "manage_request_query1";
			columns[6] = {title:"操作",width:15,render:operationFunc,align:"center",order:false};
			//discolumns = [0,1,2,3,4,5,8];
			titlename = "卡片申请单列表"
		}
			
		qt = new QueryTable(xmlShow,"searchForm","datalist",columns,{
			displayColumns:discolumns,
			title:titlename
		});
	}
	//数据处理方法
	function numFunc(v){
		return "<a href=# onclick=showDetail('"+v+"')>"+v+"</a>"
	}
	
	//处理数据 点id进入编辑页面
	function operationFunc(v,r){
		var html="<div style='color:gray'>";
		if(cOrg.orgLevel == Constants.ORG_LEVEL_HQ){
			var status = r[9];
			if(status==Constants.CARDBILL_STATUS_NEW)
				html += " <a href=# onclick=onEdit('"+r[0]+"',"+r[10]+")>修改</a> <a href=# onclick=quash4('"+r[0]+"')>删除</a> <a href=# onclick=\"confirmCard("+r[0]+",'"+r[2]+"',"+r[12]+","+r[13]+");return false;\">确认</a>";
			if(status==Constants.CARDBILL_STATUS_CONFIRM) {
				html += "<a href=# onclick=\"unConfirmCard("+r[0]+");return false;\">撤销</a>"
			}
				
		}else{
			var status = r[6];
			if(status==Constants.CARDBILL_STATUS_NEW||status==Constants.CARDBILL_STATUS_REJECTED)		//状态为‘新建’时应做的操作
				html += "<a href=# onclick=quash2('"+r[0]+"',"+r[2]+")>提交</a> "
			else
				html += "&nbsp;&nbsp;&nbsp;&nbsp;"
			if(status==Constants.CARDBILL_STATUS_NEW||status==Constants.CARDBILL_STATUS_REJECTED||status==Constants.CARDBILL_STATUS_REQUEST)
				html += " <a href=# onclick=quash1('"+r[0]+"')>撤销</a> <a href=# onclick=onEdit('"+r[0]+"',"+r[7]+")>修改</a>"
			else
				html += "&nbsp;&nbsp;&nbsp;&nbsp;"
		}
		return html;
	}
	//显示静态明细
	function showDetail(id){
		detail_editable = false;
		if (id != null){
			orderId=id
			requestframe.document.location.href = "request_order_detail.html";
			switchPage("listview1")
		}
	}

	//修改页面
	function onEdit(id,hasInfo){

	    if (id != null){
			detail_editable = true;
			if(hasInfo){
				orderId = id;
				requestframe.document.location.href = "request_order_detail.html";
				switchPage("listview1")
				return;
			}else{
				DWR.call("cardRequestService.getRequestOrder",id,function(apply){
					if(cOrg.orgLevel >= Constants.REQUEST_LOWEST_LEVEL){
						$('ismerge').innerHTML = "";
					}else{
						//$('ismerge').innerHTML = "<button type='button' name='butt' onclick='onNew()'>合并下级申请单</button>";
						$('ismerge').innerHTML = "";
					}
					if(apply.organization)
						apply.order.restrictedOrg = apply.organization.id
					Common.setValues(demandform,apply.order);
					if(cOrg.orgLevel == Constants.ORG_LEVEL_HQ){
						$("restrictedOrgSpan").style.display=""
					}else
						$("restrictedOrgSpan").style.display="none"
				
					demandform.baseCardType.value = apply.cardType.baseCardType;
					demandform.cardTypeName.value = apply.cardType.name;
					demandform.showid.value = apply.order.id;
				  	switchPage("detview");
				});
			}
		}
	}
	//确认制卡
  	function confirmCard(id,taskAmount,baseCardType,restrictedOrgId){
		if(taskAmount <= 0){
			showInformation("数量小于或等于0时不可进行制卡操作!");
			return;
		}
		var v = openDialogFrame("/store/confirm_make_card.html?id="+id+"&taskAmount="+taskAmount+"&type="+baseCardType+"&restrictedOrgId="+restrictedOrgId,'是否确认制卡',300,450);
		if (v){
			qt.showTable();	
			orderId = id;
			requestframe.document.location.href = "request_order_detail.html";
			switchPage("listview1")
		}
    }
	//撤销确认制卡
	function unConfirmCard(id){
		if(!(showQuestion("您确认要撤销单据吗?"))){
			return;
		}
		DWR.call('cardRequestService.unConfirmMakeCard',id,function(){
			showInformation("撤销成功!")
		 	qt.showTable();
         });
	}
	//撤销
	function quash(){
		var id1=$('makecardform').id.value;
		DWR.call("cardRequestService.cancelCardReqOrder",id1,function(showapply){
			 showInformation("撤销成功!");
			 switchPage("listview");
			 qt.showTable();
		},{disCtrl:$('bcz')});
	}
	//提交
	function quash3(){
		var id1=$('makecardform').id.value;
		DWR.call("cardRequestService.commitCardReqOrder",id1,function(showapply){
			 showInformation("提交成功!");
			 switchPage("listview");
			 qt.showTable();
 		},{disCtrl:$('bcz')});
	}
	//删除
	function quash5(){
		var id1=$('makecardform').id.value;
		DWR.call("cardRequestService.cancelCardReqOrder",id1,function(showapply){
			 showInformation("删除成功!");
			 switchPage("listview");
			 qt.showTable();
		},{disCtrl:$('bcz')});
	}
	function formatOrderObj(apply){
		var order = apply.order
	 	var status= order.status;
	 	order.status = Common.getText("cardbill_status",status);
		order.cardType = apply.cardType.name;
		order.createTime= Format.formatToMM(order.createTime);
		if(order.verifyTime){
			order.verifyTime = Format.formatToMM(order.verifyTime);
		}
		$("makecardform").id.value = order.id
		return order;
	}
	//撤销明细
	function quash1(id){
		DWR.call("cardRequestService.getRequestOrder",id,function(apply){
			var status = apply.order.status;
		    var order = formatOrderObj(apply)
			Common.showDetail("detread",order);
			$("query").innerHTML = "<button type='button'  id='bcz' name='bcz'  onclick='quash()' >撤   销</button> ";
	
			switchPage('detread');
		});
	}
	//提交明细
	function quash2(id,amount){
		if(amount == 0){
			showInformation("申请单的申请卡片数量为0,不能提交!");
			return;
		}	
		DWR.call("cardRequestService.getRequestOrder",id,function(apply){
			var status = apply.order.status;
		 	var order = formatOrderObj(apply)
			Common.showDetail("detread",order);
			$("query").innerHTML="<button type='button'  id='bcz' name='bcz'  onclick='quash3()'>提   交</button> ";
	
			switchPage('detread');
		});
	}
	//删除明细
	function quash4(id){
		DWR.call("cardRequestService.getRequestOrder",id,function(apply){
			var status = apply.order.status;
			var order = formatOrderObj(apply)
			Common.showDetail("detread",order);
			$("query").innerHTML="<button type='button'  id='bcz' name='bcz'  onclick='quash5()' >删   除</button> ";
	
			switchPage('detread');
		});
	}
	//修改新建制卡申请单
	function onSave(){
		if(!checkForm(demandform))return;
		var apply = Common.getValues(demandform);
		titlename=apply.cardTypeName;
		if(!(showQuestion("您确认修改卡片申请单吗?"))){
			return;
		}			
		DWR.call("cardRequestService.editReqOrderBasicInfo",apply.id,apply.completeDate,apply.amount,apply.requestComment,apply.restrictedOrg,function(showapply){
			 showInformation("修改卡片申请单成功!");
			 switchPage("listview");
			 qt.showTable();
		},{disCtrl:$('saveBtn')});
	}
	//页面刷新返回
	function backShow(){
		switchPage('listview')
		qt.showTable();
	}
	//无页面刷新返回
	function backShow1(){
		switchPage('listview')
	}
	//校验时间和显示类表数据
   function selectDate(){
		searchForm.organization.value = cOrg.id;
		qt.showTable();
   }
   //点击选择卡片方法
   function selCardType(){
	   	var v = openDialogFrame("/basic/card_type_list.html",'选择卡片类型',464,700)
	    if (v){
		    searchForm.cardType.value=v[1];
		}
   }
   function onNew(){
		type = demandform.cardType.value;
		var isPersent = false;
		var v = openDialogFrame("/store/sel_req_order.html?ct="+type+"&isPersent="+isPersent,"选择申请单",450,700);
		if (v){
			demandform.amount.value = v;
		}
	}
	</script>
</head>

<body onload="load()">
	<!--页面导航-->
	<div class="nav"><div id="nav">&nbsp;</div></div>
	<!--查询静态页面部分-->
		<div id="listview" >	
			<!--查询条件form-->
			<div class="searchForm">
				<form id="searchForm" name="searchForm">
					<input type="hidden" name="organization" >
					<table cellSpacing=0 cellPadding=6 width="100%" border=0>
						<tr>
							<td><label>单据编号</label> <input type="text" name="requestid" onblur="checkV(this,'number')" maxlength=12 ></td>
								<td id="beginDateTd"></td>
							
							<td><label>状&nbsp;&nbsp;&nbsp;&nbsp;态</label> <select name="status"><option></option></select></td>
						</tr>
						<tr>
						<td><label>卡片类型</label> <input type="text" name="cardType" maxlength=20><a class=orga title="选择卡片规格" href="javascript:void(0)" onclick="selCardType()">&nbsp;&nbsp;</a></td>
							<td id="endDateTd"></td>
							<td id="restrictedOrgTd"></td>
							<td><button type="button" onclick="selectDate()" >查   询</button></td>
						</tr>
					</table>
				</form>
			</div>
				<!--查询结构列表-->
				<div id="datalist"></div>
		</div>
		<!--新增制卡申请单-->
		<div class="detview" id="detview" style='display:none;'>
			<form id="demandform" name="demandform">
				<input type="hidden" name="id">
				<input type="hidden" name="baseCardType">
				<input type="hidden" name="cardType">
				<div class="form">
					<div class="formTitle">
						修改单据
					</div>
					<table cellSpacing=0 cellPadding=4 width="100%" border=0>
						<tr>
							<td>
								<label>单据编号</label> <input type="text" name="showid" disabled class="readonly">
							</td>
							<td>
								<label>卡片类型</label> <input type="text" name="cardTypeName" disabled class="readonly">
							</td>
						</tr>
						<tr>
							<td>
								<label>需求数量</label> <input type='text' name='amount' onblur=checkV(this,'positiveInt',true) maxlength=9><span class='des'>*</span><span id="ismerge"></span>
							</td>
							<td>
								<label>完成日期</label> <input type=text name="completeDate" onblur="checkV(this,'futureDate')" ><a href="javascript:void(0)" onclick="showDatePicker($('demandform').completeDate);" class="date" title="选择日期">&nbsp;&nbsp;</a>
							</td>
						</tr>
						<tr>
							<td>
								<label>备&nbsp;&nbsp;&nbsp;&nbsp;注</label> <input type='text' name='requestComment' id='requestComment' maxlength=64>
							</td>
							<td id="restrictedOrgSpan" style="display:none">
								<label>使用区域</label> <select name='restrictedOrg'  onblur=checkV(this,'',true)></select><span class='des'>*</span>
							</td>
						</tr>
					</table>
				</div>
				<p align="center">
					<button type='button' id='saveBtn' name='saveBtn' onclick='onSave()'>保   存</button>&nbsp;&nbsp;&nbsp;<button type='button' onclick='backShow1()' >返   回</button>
				</p>
			</form>
		</div>
		<!--明细静态显示部分-->
	<div class="detread" id="detread" style='display:none;'>
		<form id="makecardform" name="makecardform">
		<input type="hidden" name="id">
			<div class=form>
			<div class="formTitle">单据明细</div>
				<table cellSpacing=0 cellPadding=4 width="100%" border=0 class="viewTable">
					<tr>
						<td>
							<label>单据编号</label> <span id="id"></span>
						</td>
						<td>
							<label>卡片类型</label> <span id="cardType"></span>
						</td>
					</tr>
					<tr>
						<td>
							<label>需求数量</label> <span id="amount"></span>
						</td>
						<td>
							<label>状&nbsp;&nbsp;&nbsp;&nbsp;态</label> <span id="status"></span>
						</td>
					</tr>
					<tr>
						<td>
							<label>创建时间</label> <span id="createTime"></span>
						</td>
						<td>
							<label>完成日期</label> <span id="completeDate"></span>
						</td>						
					</tr>
					<tr>
						<td>
							<label>备&nbsp;&nbsp;&nbsp;&nbsp;注</label> <span id="requestComment"></span>
						</td>
						<td id="onpassspan">	
						</td>
					</tr>
				</table>
			</div>
			<p><span id="query"></span><button type="button" onclick="backShow1()">返   回</button></p>
		</form>
	</div>
	<div class="listview1" id="listview1" style='display:none;'>
		<iframe id="requestframe" name="requestframe" style="width:100%;height:90%;overflow:auto;" frameborder=0 src=""></iframe>
	</div>
</body>
</html>